<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申请单号" prop="applyNo">
        <el-input v-model="queryParams.applyNo" placeholder="请输入申请单号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="申请类型" prop="applyType">
        <el-select v-model="queryParams.applyType" placeholder="请选择申请类型" clearable filterable size="small">
          <el-option v-for="dict in applyTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="计划单号" prop="planNo">
        <el-input v-model="queryParams.planNo" placeholder="请输入计划单号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="申请人" prop="applyUser">
        <el-select v-model="queryParams.applyUser" placeholder="请选择申请人" clearable filterable size="small">
          <el-option v-for="dict in applyUserOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="申请日期">
        <el-date-picker v-model="daterangeApplyTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="申请状态" prop="applyStatus">
        <el-select v-model="queryParams.applyStatus" placeholder="请选择申请状态" clearable filterable size="small">
          <el-option v-for="dict in applyStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="审核人" prop="auditUser">
        <el-select v-model="queryParams.auditUser" placeholder="请选择审核人" clearable filterable size="small">
          <el-option v-for="dict in auditUserOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="审核日期">
        <el-date-picker v-model="daterangeAuditTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable filterable size="small">
          <el-option v-for="dict in auditStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button v-no-more-click type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button v-no-more-click icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-no-more-click type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['purchase:apply:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-no-more-click type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['purchase:apply:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-no-more-click type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['purchase:apply:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="申请单号" align="center" prop="applyNo" width="150" />
      <el-table-column label="申请类型" align="center" prop="applyType" :formatter="applyTypeFormat" />
      <el-table-column label="计划单号" align="center" prop="planNo" width="150">
        <template slot-scope="scope">
          <el-link type="primary" @click="handleOpenPlan(scope.row.planId)">{{scope.row.planNo}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="补货单号" align="center" prop="replenishNo" width="150"></el-table-column>
      <el-table-column label="申请人" align="center" prop="applyUser" :formatter="applyUserFormat" />
      <el-table-column label="申请日期" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请状态" align="center" prop="applyStatus" :formatter="applyStatusFormat" />
      <el-table-column label="审核人" align="center" prop="auditUser" :formatter="auditUserFormat" />
      <el-table-column label="审核日期" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditStatus" :formatter="auditStatusFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-no-more-click size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['purchase:apply:edit']">修改</el-button>
          <el-button v-no-more-click size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-show="scope.row.auditStatus!='1'&&scope.row.applyStatus!='1'" v-hasPermi="['purchase:apply:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改采购申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="申请单号" prop="applyNo">
          <el-input v-model="form.applyNo" placeholder="-系统自动生成" disabled />
        </el-form-item>
        <el-form-item label="计划单号" prop="planNo">
          <el-input v-model="form.planNo" disabled>
            <el-button v-no-more-click slot="append" @click="handleSelectPlan"
              :disabled="form.auditStatus!='1'&&form.applyStatus!='1'?false:true">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="申请人" prop="applyUser">
          <el-select v-model="form.applyUser" placeholder="" clearable filterable disabled>
            <el-option v-for="dict in applyUserOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请日期" prop="applyTime">
          <el-date-picker clearable size="small" v-model="form.applyTime" type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss" placeholder="" disabled>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="申请状态" prop="applyStatus">
          <el-select v-model="form.applyStatus" placeholder="" clearable filterable disabled>
            <el-option v-for="dict in applyStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="auditUser">
          <el-select v-model="form.auditUser" placeholder="" clearable filterable disabled>
            <el-option v-for="dict in auditUserOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核日期" prop="auditTime">
          <el-date-picker clearable size="small" v-model="form.auditTime" type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss" placeholder="" disabled>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核状态" prop="auditStatus">
          <el-select v-model="form.auditStatus" placeholder="" clearable filterable disabled>
            <el-option v-for="dict in auditStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核意见" prop="auditComment">
          <el-input v-model="form.auditComment" type="textarea" placeholder="" disabled />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-divider content-position="center">采购申请明细信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button v-no-more-click v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="primary" icon="el-icon-plus"
              size="mini" @click="handleAddScmPurchaseApplyDetail">添加
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button v-no-more-click v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="danger" icon="el-icon-delete"
              size="mini" @click="handleDeleteScmPurchaseApplyDetail">删除
            </el-button>
          </el-col>
        </el-row>
        <el-table :data="scmPurchaseApplyDetailList" :row-class-name="rowScmPurchaseApplyDetailIndex"
          @selection-change="handleScmPurchaseApplyDetailSelectionChange" ref="scmPurchaseApplyDetail">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50" />
          <el-table-column label="物料" prop="materialName" width="300">
            <template slot-scope="scope">
              <el-form-item :prop="'scmPurchaseApplyDetailList.'+scope.$index+'.materialName'"
                :rules="rules.materialName">
                <el-input v-model="scope.row.materialName" placeholder="请选择物料" disabled>
                  <el-button v-no-more-click slot="append" @click="handleSelectMaterial(scope.$index)"
                    :disabled="form.auditStatus!='1'&&form.applyStatus!='1'?false:true">选择</el-button>
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="型号" prop="materialModel"></el-table-column>
          <el-table-column label="规格" prop="materialSpecification"></el-table-column>
          <el-table-column label="单位" prop="materialUnit"></el-table-column>
          <el-table-column label="单价" prop="price" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'scmPurchaseApplyDetailList.'+scope.$index+'.price'" :rules="rules.price">
                <el-input v-model="scope.row.price" placeholder="请输入单价" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="采购数量" prop="quantity" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'scmPurchaseApplyDetailList.'+scope.$index+'.quantity'" :rules="rules.quantity">
                <el-input v-model="scope.row.quantity" placeholder="请输入采购数量" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="需求数量" prop="requireQuantity" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'scmPurchaseApplyDetailList.'+scope.$index+'.requireQuantity'"
                :rules="rules.requireQuantity">
                <el-input v-model="scope.row.requireQuantity" placeholder="请输入需求数量" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="需求日期" prop="requireDate" width="240">
            <template slot-scope="scope">
              <el-form-item :prop="'scmPurchaseApplyDetailList.'+scope.$index+'.requireDate'"
                :rules="rules.requireDate">
                <el-date-picker clearable v-model="scope.row.requireDate" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择需求日期" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="detailRemark" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'scmPurchaseApplyDetailList.'+scope.$index+'.detailRemark'"
                :rules="rules.detailRemark">
                <el-input v-model="scope.row.detailRemark" placeholder="请输入备注" />
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-no-more-click v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="primary" @click="saveForm">保 存</el-button>
        <el-button v-no-more-click v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="warning" @click="submitForm">提 交
        </el-button>
        <el-button v-no-more-click @click="cancel">取 消</el-button>
      </div>
      <!--选择计划-->
      <PlanSelect :open="planSelectOpen" @onPlanCancel="handlePlanCancel" @onPlanSelected="handlePlanSelected">
      </PlanSelect>
    </el-dialog>
    <!--选择物料档案-->
    <MaterialSelect :open="materialSelectOpen" @onCancel="handleMaterialCancel" @onSelected="handleMaterialSelected">
    </MaterialSelect>
    <PurchasePlanDetail :open="planDetailOpen" :planId="planId" @onPlanDetailCancel="handlePlanDetailCancel">
    </PurchasePlanDetail>
  </div>
</template>

<script>
  import {
    listApply,
    getApply,
    delApply,
    addApply,
    updateApply,
    exportApply,
    submitApply,
    listApplyDetailByPlanId
  } from "@/api/purchase/apply";

  import MaterialSelect from "@/components/Material/MaterialSelect";
  import PlanSelect from "@/components/Purchase/PlanSelect";
  import PurchasePlanDetail from '../components/PurchasePlanDetail.vue';
  export default {
    name: "Apply",
    components: {
      MaterialSelect,
      PlanSelect,
      PurchasePlanDetail
    },
    data() {
      return {
        planId: null,
        planDetailOpen: false,
        planSelectOpen: false,
        material: null,
        currentRowIndex: null,
        materialSelectOpen: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 子表选中数据
        checkedScmPurchaseApplyDetail: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 采购申请表格数据
        applyList: [],
        // 采购申请明细表格数据
        scmPurchaseApplyDetailList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 申请人字典
        applyUserOptions: [],
        // 申请日期时间范围
        daterangeApplyTime: [],
        // 申请类别字典
        applyTypeOptions: [],
        // 申请状态字典
        applyStatusOptions: [],
        // 审核人字典
        auditUserOptions: [],
        // 审核日期时间范围
        daterangeAuditTime: [],
        // 审核状态字典
        auditStatusOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          applyNo: null,
          planNo: null,
          applyType: null,
          applyUser: null,
          applyTime: null,
          applyStatus: null,
          auditUser: null,
          auditTime: null,
          auditStatus: null,
          orderByColumn: 'apply_time',
          isAsc: 'desc',
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          materialName: [{
            required: true,
            message: "物料不能为空",
            trigger: "blur"
          }],
          quantity: [{
            required: true,
            message: "采购数量不能为空",
            trigger: "blur"
          }],
          requireQuantity: [{
            required: true,
            message: "需求数量不能为空",
            trigger: "blur"
          }],
          requireDate: [{
            required: true,
            message: "需求日期不能为空",
            trigger: "blur"
          }],
        }
      };
    },
    created() {
      this.getList();
      this.getQueryData("query_user").then(res => {
        this.applyUserOptions = res.data;
      });
      this.getDicts("apply_status").then(response => {
        this.applyStatusOptions = response.data;
      });
      this.getQueryData("query_user").then(res => {
        this.auditUserOptions = res.data;
      });
      this.getDicts("audit_status").then(response => {
        this.auditStatusOptions = response.data;
      });
      this.getDicts("purchase_apply_type").then(response => {
        this.applyTypeOptions = response.data;
      });
    },
    watch: {
      'scmPurchaseApplyDetailList': {
        handler(newVal, oldVal) {
          this.form.scmPurchaseApplyDetailList = newVal;
        },
        immediate: true,
        deep: true,
      }
    },

    methods: {
      //点击承运单号处理函数
      handleOpenPlan(id) {
        this.planId = id;
        this.planDetailOpen = true;
      },
      handlePlanDetailCancel() {
        this.planDetailOpen = false;
      },
      //选择计划回调函数
      handlePlanSelected(list) {
        if (list && list.length > 0) {
          let plan = list[0];
          this.form.planId = plan.id;
          this.form.planNo = plan.purchasePlanNo
          // 根据计划id获取applyDetailList
          listApplyDetailByPlanId(plan.id).then(res => {
            this.scmPurchaseApplyDetailList = res.data;
          })
        }
        this.planSelectOpen = false;
      },
      //选择计划
      handleSelectPlan() {
        this.planSelectOpen = true;
      },
      //取消选择计划
      handlePlanCancel() {
        this.planSelectOpen = false;
      },
      //选择物料处理函数
      handleSelectMaterial(index) {
        this.materialSelectOpen = true;
        this.currentRowIndex = index;
      },
      handleMaterialCancel() {
        this.materialSelectOpen = false;
      },
      //选择物料回调函数
      handleMaterialSelected(list) {
        if (list && list.length > 0) {
          this.material = list[0];
          this.scmPurchaseApplyDetailList[this.currentRowIndex].materialId = this.material.id;
          this.scmPurchaseApplyDetailList[this.currentRowIndex].materialName = this.material.name;
          this.scmPurchaseApplyDetailList[this.currentRowIndex].materialCode = this.material.code;
          this.scmPurchaseApplyDetailList[this.currentRowIndex].materialModel = this.material.model;
          this.scmPurchaseApplyDetailList[this.currentRowIndex].materialSpecification = this.material.specification;
          this.scmPurchaseApplyDetailList[this.currentRowIndex].materialUnit = this.material.unit;
          this.scmPurchaseApplyDetailList[this.currentRowIndex].price = this.material.price;
        }
        this.materialSelectOpen = false;
      },
      /** 查询采购申请列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        if (null != this.daterangeApplyTime && '' != this.daterangeApplyTime) {
          this.queryParams.params["beginApplyTime"] = this.daterangeApplyTime[0];
          this.queryParams.params["endApplyTime"] = this.daterangeApplyTime[1];
        }
        if (null != this.daterangeAuditTime && '' != this.daterangeAuditTime) {
          this.queryParams.params["beginAuditTime"] = this.daterangeAuditTime[0];
          this.queryParams.params["endAuditTime"] = this.daterangeAuditTime[1];
        }
        listApply(this.queryParams).then(response => {
          this.applyList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 申请类别字典翻译
      applyTypeFormat(row, column) {
        return this.selectDictLabel(this.applyTypeOptions, row.applyType);
      },
      // 申请人字典翻译
      applyUserFormat(row, column) {
        return this.selectDictLabel(this.applyUserOptions, row.applyUser);
      },

      // 申请状态字典翻译
      applyStatusFormat(row, column) {
        return this.selectDictLabel(this.applyStatusOptions, row.applyStatus);
      },
      // 审核人字典翻译
      auditUserFormat(row, column) {
        return this.selectDictLabel(this.auditUserOptions, row.auditUser);
      },
      // 审核状态字典翻译
      auditStatusFormat(row, column) {
        return this.selectDictLabel(this.auditStatusOptions, row.auditStatus);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          applyNo: null,
          planId: null,
          planNo: null,
          applyUser: null,
          applyTime: null,
          applyStatus: null,
          auditUser: null,
          auditTime: null,
          auditStatus: null,
          auditComment: null,
          remark: null,
          scmPurchaseApplyDetailList: [],
        };
        this.scmPurchaseApplyDetailList = [];
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeApplyTime = [];
        this.daterangeAuditTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        // this.ids = selection.map(item => item.id)
        let filters = selection.filter(item => item.auditStatus != '1');
        this.ids = filters.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加采购申请";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getApply(id).then(response => {
          this.form = response.data;
          this.scmPurchaseApplyDetailList = response.data.scmPurchaseApplyDetailList;
          this.open = true;
          this.title = "修改采购申请";
        });
      },
      /** 保存按钮 */
      saveForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (!this.scmPurchaseApplyDetailList || this.scmPurchaseApplyDetailList.length == 0) {
              this.msgError('请添加物料');
              return false;
            }
            if (this.form.id != null) {
              updateApply(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addApply(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            submitApply(this.form).then(response => {
              this.msgSuccess("提交成功");
              this.open = false;
              this.getList();
            });
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除采购申请编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delApply(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 采购申请明细序号 */
      rowScmPurchaseApplyDetailIndex({
        row,
        rowIndex
      }) {
        row.index = rowIndex + 1;
      },

      /** 采购申请明细添加按钮操作 */
      handleAddScmPurchaseApplyDetail() {
        let obj = {};
        obj.materialId = "";
        obj.price = "";
        obj.quantity = "";
        obj.requireQuantity = "";
        obj.requireDate = "";
        obj.detailRemark = "";
        obj.materialName = "";
        obj.materialModel = "";
        obj.materialSpecification = "";
        obj.materialUnit = "";
        this.scmPurchaseApplyDetailList.push(obj);
      },
      /** 采购申请明细删除按钮操作 */
      handleDeleteScmPurchaseApplyDetail() {
        if (this.checkedScmPurchaseApplyDetail.length == 0) {
          this.$alert("请先选择要删除的采购申请明细数据", "提示", {
            confirmButtonText: "确定",
          });
        } else {
          this.scmPurchaseApplyDetailList.splice(this.checkedScmPurchaseApplyDetail[0].index - 1, 1);
        }
      },
      /** 单选框选中数据 */
      handleScmPurchaseApplyDetailSelectionChange(selection) {
        if (selection.length > 1) {
          this.$refs.scmPurchaseApplyDetail.clearSelection();
          this.$refs.scmPurchaseApplyDetail.toggleRowSelection(selection.pop());
        } else {
          this.checkedScmPurchaseApplyDetail = selection;
        }
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有采购申请数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return exportApply(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };

</script>
